package com.example.managesystem.controller.teacher;

import com.example.managesystem.dto.*;
import com.example.managesystem.result.Result;
import com.example.managesystem.service.AnnoService;
import com.example.managesystem.service.ItemService;
import com.example.managesystem.service.TimeService;
import com.example.managesystem.service.UserService;
import com.example.managesystem.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
//import io.swagger.v3.oas.annotations.parameters.RequestBody;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@CrossOrigin(origins = "*") //origins可以指定请求来源，*代表全部
@Api(tags = "教师端")
@RequestMapping("/tea")
public class TeacherController {
    @Autowired
    private UserService userService;
    @Autowired
    private AnnoService annoService;
    @Autowired
    private ItemService itemService;
    @Autowired
    private TimeService timeService;

    /**
     * 时间发布
     * @param timeDto
     * @return
     */
    @PostMapping("/time")
    @ApiOperation(value = "发布时间")
    public Result postTime(@RequestBody TimeDto timeDto){
        log.info("发布时间");
        log.info("发布时间{}",timeDto);
        timeService.insertTime(timeDto);
        return Result.success();
    }

    /**
     * 批量删除公告
     * @param annoids
     * @return
     */
   @DeleteMapping("/deleteAnnos")
    public Result deleteAnnos(@RequestParam List<Long> annoids){
        log.info("批量删除公告{}",annoids);
        annoService.deleteAnnos(annoids);
        return Result.success();
    }

    /**
     * 查看项目细节详情
     * @param item_id
     * @return
     */
    @GetMapping("/itemdetail")
    @ApiOperation(value = "项目细节详情")
    public Result<PostItemVO> lookItemDetails(Integer item_id){
        log.info("项目细节详情");
        PostItemVO postItemVO=itemService.lookItemDetails(item_id);
        return Result.success(postItemVO);
    }

    /**
     * 获取需要审核立项申请的项目
     * @return
     */
    @GetMapping("/examineSetupItems")
    @ApiOperation(value = "获取需要审核立项申请的项目")
    public Result<ExamineSetupItemsVO> getExamineSetupItems(){
        ExamineSetupItemsVO examineSetupItemsVO=itemService.getExamineSetupItems();
        return Result.success(examineSetupItemsVO);
    }


    /**
     * 提交结项材料
     * @param item_id
     * @return
     */
    @GetMapping("/prepareScore")
    @ApiOperation(value = "准备评分")
    public Result prepareScore(Integer item_id){
        log.info("准备评分");
        PrepareScoreVO prepareScoreVO=itemService.prepareScore(item_id);
        return Result.success(prepareScoreVO);
    }

    /**
     * 对等待立项审核的项目评分
     * @param examineScoreDTO
     * @return
     */
    @PostMapping("scoreSetupItem")
    public Result scoreSetupItem(@RequestBody ExamineScoreDTO  examineScoreDTO){
        log.info("对等待立项审核的项目评分");
        itemService.scoreSetupItem(examineScoreDTO);
        return Result.success();
    }

    /**
     * 获取需要审核进展记录的项目
     * @return
     */
    @GetMapping("/examineProgressItems")
    @ApiOperation(value = "获取需要审核进展记录的项目")
    public Result<ExamineProgressItemsVO> getExamineProgressItems(){
        ExamineProgressItemsVO examineProgressItemsVO=itemService.getExamineProgressItems();
        return Result.success(examineProgressItemsVO);
    }
    /**
     * 需要中期审核的项目
     * @return
     */
    @GetMapping("/examineMiditems")
    @ApiOperation(value = "需要中项审核的项目")
    public Result<ExamineMidItermsVO> getMidterm(){
        log.info("需要进行中期检查的项目");
        ExamineMidItermsVO examineMidItermsVO=itemService.getExamineMidterms();
        return Result.success(examineMidItermsVO);
    }

    /**
     * 准备审核中期项目
     * @param itemId
     * @return
     */
    @GetMapping("/prepareMiditem")
    @ApiOperation(value = "准备审核中期项目")
    public Result prepareMiditem(Integer itemId){
        log.info("准备中期报告");
        PrepareMiditemVO prepareMiditemVO=itemService.prepareMiditem(itemId);
        return Result.success(prepareMiditemVO);
    }

    /**
     * 对等待中期审核的项目评分
     * @param examineScoreMidItem
     * @return
     */
    @PostMapping("scoreMidItem")
    public Result scoreMidItem(@RequestBody ExamineScoreDTO examineScoreMidItem){
        log.info("对等待中期审核的项目评分");
        itemService.scoreMidItem(examineScoreMidItem);
        return Result.success();
    }

    /**
     * 准备下载文件
     * @return
     */
    @GetMapping("/prepareDownloadFiles")
    @ApiOperation(value = "准备下载文件")
    public Result prepareDownloadFiles(){
        DownloadFilesVO downloadFilesVO=itemService.prepareDownloadFiles();
        return Result.success(downloadFilesVO);
    }

    /**
     * 根据格式下载文件
     * @param typeDownloadFileDTO
     * @return
     */
    @PostMapping("/downloadFiles")
    @ApiOperation(value = "根据格式下载文件")
    public Result downloadFiles(@RequestBody TypeDownloadFileDTO typeDownloadFileDTO){
        FileMainsVO fileMainsVO=itemService.downloadFiles(typeDownloadFileDTO);
        return Result.success(fileMainsVO);
    }
    /**
     * 需要结项审核的项目
     * @return
     */
    @GetMapping("/examineCompleteditems")
    @ApiOperation(value = "需要结项审核的项目")
    public Result<ExamineCompletedItemsVO> getCompletedterm(){
        log.info("需要进行结项审核的项目");
        ExamineCompletedItemsVO examineCompletedItemsVO =itemService.getCompeletedIterms();
        return Result.success(examineCompletedItemsVO);
    }
    /**
     * 对等待结项审核的项目评分
     * @param examineScoreDTO
     * @return
     */
    @PostMapping("scoreCompletedItem")
    @ApiOperation(value = "对等待结项审核的项目评分")
    public Result scoreCompletedItem(@RequestBody ExamineScoreDTO examineScoreDTO){
        log.info("对等待结项审核的项目评分");
        itemService.scoreCompletedItem(examineScoreDTO);
        return Result.success();
    }
    /**
     * 需要延期结项审核的项目
     * @return
     */
    @GetMapping("/examineDelayitems")
    @ApiOperation(value = "需要延期结项审核的项目")
    public Result<ExamineDelayItemsVO> examineDelayitems(){
        log.info("需要进行延期结项审核的项目");
        ExamineDelayItemsVO examineDelayItemsVO=itemService.getDelayitems();
        return Result.success(examineDelayItemsVO);
    }
    /**
     * 对等待延期结项审核的项目评分
     * @param examineScoreDTO
     * @return
     */
    @PostMapping("scoreDelayItem")
    @ApiOperation(value = "对等待延期审核的项目评分")
    public Result scoreDelayItem(@RequestBody ExamineScoreDTO examineScoreDTO){
        log.info("对等待延期结项审核的项目评分");
        itemService.scoreDelayItem(examineScoreDTO);
        return Result.success();
    }

    /**
     * 发布公告
     * @param annoDTO
     * @return
     */
    @PostMapping("postAnno")
    @ApiOperation(value = "发布公告")
     public Result postAnno(@RequestBody AnnoDTO annoDTO){
        log.info("发布公告");
        annoService.postAnno(annoDTO);
        return  Result.success();
     }

}
